﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


using System.Threading;
using System.IO;
using System.Xml;
using System.Web;
using System.Runtime.InteropServices;
using System.IO.Ports;
using weiqijiance;
using ZedGraph;
using CCWin;
namespace weiqijiance.国标自检类
{
    public partial class JDXiangYSJ : CCSkinMain
    {
        public mainform m_mainform;

        public Thread t1;
        public Thread t2;

        int idijizu = 0;
        double fxysj = 0;
        //float fspeedstart = 0;
        float fspeedend = 0;
        float fpowerstart = 0;
        float fpowerend = 0;

        public float fpower;

        public float DIW;

        double[] dtimex = new double[10000];
        double[] dSP = new double[10000];
        double[] dPW = new double[10000];
        double[] dFC = new double[10000];

        DateTime dstartgcsj;
        public int igcsj;

        public float m_fspeed;
        public float fForce;

        public string sASMJGXZ;//是否进行结果修正
        public int iASMtdz;//ASM信号左通道
        public int iASMtdy;//ASM信号右通道
        public int iASMtdh;//ASM信号右通道
        public int iASMHWQ;//ASM到位红外

        public int iASMKZJSS;//ASM举升升
        public int iASMKZJSJ;//ASM举升降
        public int iASMSDtd;//车速信号接在那个通道



        public JDXiangYSJ()
        {
            InitializeComponent();
        }

        #region 控件大小随窗体大小等比例缩放
        private float x;//定义当前窗体的宽度
        private float y;//定义当前窗体的高度
        private void setTag(Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ";" + con.Height + ";" + con.Left + ";" + con.Top + ";" + con.Font.Size;
                if (con.Controls.Count > 0)
                {
                    setTag(con);
                }
            }
        }
        private void setControls(float newx, float newy, Control cons)
        {
            //遍历窗体中的控件，重新设置控件的值
            foreach (Control con in cons.Controls)
            {
                //获取控件的Tag属性值，并分割后存储字符串数组
                if (con.Tag != null)
                {
                    string[] mytag = con.Tag.ToString().Split(new char[] { ';' });
                    //根据窗体缩放的比例确定控件的值
                    con.Width = Convert.ToInt32(System.Convert.ToSingle(mytag[0]) * newx);//宽度
                    con.Height = Convert.ToInt32(System.Convert.ToSingle(mytag[1]) * newy);//高度
                    con.Left = Convert.ToInt32(System.Convert.ToSingle(mytag[2]) * newx);//左边距
                    con.Top = Convert.ToInt32(System.Convert.ToSingle(mytag[3]) * newy);//顶边距
                    Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;//字体大小
                    con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
                    if (con.Controls.Count > 0)
                    {
                        setControls(newx, newy, con);
                    }
                }
            }
        }
        #endregion

        private void JDXiangYSJ_Resize(object sender, EventArgs e)
        {
            float newx = (this.Width) / x;
            float newy = (this.Height) / y;
            setControls(newx, newy, this);
        }

        public void gettongdao()
        {

            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\串口及通道设置.ini";
            string path1 = string.Format(@"{0}", path);
            m_mainform.Ini(path1);

            ///读取检定数据

            for (int i = 0; i < 10; i++)
            {
                string sgetname = m_mainform.ReadValue("通道设置", string.Format(@"模拟信号{0}", i + 1));
                if (sgetname.Contains("测功力左"))
                {
                    iASMtdz = i;
                }

                if (sgetname.Contains("测功力右"))
                {
                    iASMtdy = i;
                }

                if (sgetname.Contains("测功力后"))
                {
                    iASMtdh = i;
                }
            }

            for (int i = 0; i < 8; i++)
            {
                string smaichong = m_mainform.ReadValue("通道设置", string.Format(@"速度{0}", i + 1));
                if (smaichong.Contains("速度"))
                {
                    iASMSDtd = i;
                }

            }

            ///控制
            for (int i = 0; i < 8; i++)
            {

                string shongwai = m_mainform.ReadValue("通道设置", string.Format(@"控制{0}", i + 1));
                if (shongwai.Contains("测功举升升"))
                {
                    iASMKZJSS = i;
                }
                if (shongwai.Contains("测功举升降"))
                {
                    iASMKZJSJ = i;
                }
            }
        }

        public void setsssj()
        {
            text_li.Text = fForce.ToString("0.0");
            text_sudu.Text = m_fspeed.ToString("0.0");
            txtgl.Text = fpower.ToString("0.0");
        }

        public void setjcjg()
        {
            if(idijizu==1)
                txtxysj1.Text = fxysj.ToString("0.0");
            if (idijizu == 2)
                txtxysj2.Text = fxysj.ToString("0.0");
            if (idijizu == 3)
                txtxysj3.Text = fxysj.ToString("0.0");
            if (idijizu == 4)
                txtxysj4.Text = fxysj.ToString("0.0");
            if (idijizu == 5)
                txtxysj5.Text = fxysj.ToString("0.0");
            if (idijizu == 6)
                txtxysj6.Text = fxysj.ToString("0.0");
            if (idijizu == 7)
                txtxysj7.Text = fxysj.ToString("0.0");
            if (idijizu == 8)
                txtxysj8.Text = fxysj.ToString("0.0");
        }
        public void WriteGraph(ZedGraphControl zgc, double[] izdz, double[] izdy, int icount)
        {
            MethodInvoker ln = new MethodInvoker(setsssj);
            this.BeginInvoke(ln);
            double imax = 0;
            for (int i = 0; i < icount; i++)
            {
                if (imax < izdz[i])
                {
                    imax = izdz[i];
                }
            }
            imax = imax * 1.1;
            for (int i = 0; i < icount; i++)
            {

                if (imax < izdy[i])
                {
                    imax = izdy[i];
                }

            }
            imax = imax * 1.1;

            GraphPane myPane = zgc.GraphPane;
            myPane.Fill = new Fill(Color.White, Color.Aqua, 45.0f);
            myPane.Legend.Fill = new Fill(Color.Gainsboro);
            myPane.Chart.Fill = new Fill(Color.Gainsboro);

            myPane.CurveList.Clear();

            myPane.Title.Text = string.Format("曲线");

            myPane.XAxis.Title.Text = "时间(s)";
            myPane.YAxis.Title.Text = "速度(km/h)";

            myPane.YAxis.MajorGrid.IsVisible = false;
            myPane.YAxis.MinorTic.Size = 0f;

            myPane.YAxis.Scale.Min = 0;
            myPane.YAxis.Scale.Max = imax + 0;
            myPane.YAxis.Scale.MajorStep = 10;

            zgc.IsShowPointValues = true;//数据节点
            string ss0 = string.Format("速度");
            string ss1 = string.Format("功率");

            PointPairList list0 = new PointPairList();
            PointPairList list1 = new PointPairList();


            LineItem myCurve0 = myPane.AddCurve(ss0, list0, Color.Blue,
                                    SymbolType.None);
            LineItem myCurve1 = myPane.AddCurve(ss1, list1, Color.Red,
                                    SymbolType.None);
            myCurve0.Line.Width = 1.7F;
            myCurve1.Line.Width = 1.7F;

            for (int i = 0; i < icount; i++)
            {
                list0.Add(i, izdz[i]);
                list1.Add(i, izdy[i]);
            }
            zgc.AxisChange();
            zgc.Invalidate();
        }


        private void JDXiangYSJ_Load(object sender, EventArgs e)
        {
            textBox1.Text = m_mainform.stationCode;
            textBox2.Text = m_mainform.lineCode;
            textBox3.Text = DateTime.Now.ToString("yyyy-MM-dd");
            gettongdao();
            m_mainform.DAC.tiaoling(1);//调零
            ///读取检定数据
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\设备检定结果.ini";
            string path1 = string.Format(@"{0}", path);
            m_mainform.Ini(path1);

            float.TryParse(m_mainform.ReadValue("惯量检定", "惯量"), out DIW);
            if (DIW < 1)
            {
                DIW = 900;
            }
            x = this.Width;
            y = this.Height;
            setTag(this);
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
        }
        bool bxc1 = false;
        bool bxc2 = false;
        private void skinButton2_Click(object sender, EventArgs e)
        {
            if (bxc1 || bxc2)
            {
                MessageBox.Show("内部线程还在进行，请等待完成再检测或者关闭软件再打开");
                return;
            }
            idijizu = 1;
            float.TryParse(txtspeed1.Text, out fspeedend);
            float.TryParse(txtstartpower1.Text, out fpowerstart);
            float.TryParse(txtendpower1.Text, out fpowerend);

             m_mainform.DAC.Lift(false);
            Thread.Sleep(1500);

            m_mainform.DAC.PutVol(0);
            Thread.Sleep(1000);
            m_mainform.BianPinQi(true);
            Thread.Sleep(3000);
            m_mainform.BianPinQiSpeed(256 * 40);//设置频率
            bxc1 = true;
            bxc2 = true;
            t1 = new Thread(new ThreadStart(Thread1));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();
            t2 = new Thread(new ThreadStart(Thread2));
            t2.Priority = ThreadPriority.BelowNormal;
            t2.Start();
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            try
            {
                t1.Abort();
                t1.DisableComObjectEagerCleanup();

            }
            catch (Exception)
            { }
            try
            {
                t2.Abort();
                t2.DisableComObjectEagerCleanup();
            }
            catch (Exception)
            { }
            bxc1 = false;
            bxc2 = false;
            m_mainform.DAC.PutVol(0);
            Thread.Sleep(1000);
            m_mainform.BianPinQi(false);
        }

        //bool bPutVolstart = false;
        public void getstart(double fspeed)//到达开始检测的速度
        {
            try
            {
                DateTime dpinlv = DateTime.Now;
                dstartgcsj = DateTime.Now;
                while (true)
                {
                    Thread.Sleep(20);
                    if (m_fspeed > fspeed)
                    {
                        m_mainform.BianPinQi(false); ;//关闭电源电源
                        //bPutVolstart = true;
                        break;
                    }
                    float fgonglv = (fForce * m_fspeed) / 360;
                }
            }
            catch
            {
                m_mainform.BianPinQi(false); ;//关闭电源电源
            }
        }
        public float getbljj(float forcedq, float forcejs)
        {
            float fbljj = 0;
            if (forcedq / forcejs > 1.04)
            {
                fbljj = -5;// 1 - forcedq / forcejs;

            }
            if (forcedq / forcejs < 0.96)
            {
                fbljj = 5;// 1 - forcedq / forcejs;

            }
            return fbljj;
        }
        public float getforcevol(float fmbforce,double dvol)
        {
            try
            {
                DateTime dtwoliusj = DateTime.Now;
                DateTime dpinlv = DateTime.Now;
                //float izzmz = 0;
                float fwoliu =  m_mainform.DAC.getwoliu("涡流输出", fmbforce);
                float fwoliulast = fwoliu;
                if (dvol > 100)
                {
                    fwoliu = (float)dvol;
                }
                while (true)
                {
                    Thread.Sleep(10);
                    if (fForce <= fmbforce + 4 && fForce >= fmbforce - 4)
                    {//记录结束滑行时间
                        return fwoliulast;
                    }
                    if (JDhelpClass.DateDiff(DateTime.Now, dtwoliusj) >= 300)
                    {
                        float forcedq;
                        forcedq = fForce;
                        float fblz = 0;
                        fblz = getbljj(forcedq, (float)fmbforce);
                        //izzmz += fblz;
                        fwoliulast = fwoliu;
                        fwoliu = fwoliu + fblz;
                        m_mainform.DAC.PutVol(fwoliu);//
                        dtwoliusj = DateTime.Now;
                    }

                    string syy = DateTime.Now.ToString("yyyy");
                    string smm = DateTime.Now.ToString("MM");
                    string sdd = DateTime.Now.ToString("dd");
                    string smul = string.Format("{0}\\{1}\\{2}\\{3}", System.Windows.Forms.Application.StartupPath, syy, smm, sdd);
                    if (!Directory.Exists(smul))
                    {
                        Directory.CreateDirectory(smul);
                    }
                    string path = "";
                    path = string.Format("{0}\\{1}.ini", smul, "响应时间过程数据");
                    iniclass objini = new iniclass();
                    objini.Ini(path);
                    string siniwrite = string.Format("码值：{0}，速度：{1}，力：{2},功率：{3}",
                      fwoliu.ToString("0"), m_fspeed.ToString("0.0"), fForce.ToString("0.0"), (m_fspeed * fForce / 360f).ToString("0.0"));
                    objini.Writue("响应时间过程数据" + DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), siniwrite);

                }
            }
            catch(Exception )
            {

            }
            return 0;
        }
        public void ctrlshuchu(double fspeedstart, double fspeedend, double fpowerstart,double fpowerend)
        {
            double fstartforce = fpowerstart * 360 / fspeedend;
            double fendforce = fpowerend * 360 / fspeedend;
            double dmaxforce = Math.Max(fstartforce, fendforce);
            double dminforce = Math.Min(fstartforce, fendforce);
            double dstartvol = 0, dendvol = 0;
            try
            {
                while (true)
                {
                    Thread.Sleep(20);
                    if (m_fspeed < fspeedstart)
                    {
                        m_mainform.BianPinQi(false); ;//关闭电源电源
                        //bPutVolstart = true;
                        break;
                    }
                }

                string path = "";
                path = System.Windows.Forms.Application.StartupPath + path + "\\设备检定结果.ini";
                string path1 = string.Format(@"{0}", path);
                iniclass objini = new iniclass();
                objini.Ini(path1);
                float fvol1 = 0, fvol2 = 0;
                float.TryParse(objini.ReadValue("自检响应时间", string.Format("{0}{1}", fspeedend, fpowerstart)), out fvol1);
                float.TryParse(objini.ReadValue("自检响应时间", string.Format("{0}{1}", fspeedend, fpowerend)), out fvol2);

                float fvolmin = getforcevol((float)dminforce,Math.Min(fvol1,fvol2));
                float fvolmax = getforcevol((float)dmaxforce, Math.Max(fvol1, fvol2));
                m_mainform.baocunRJ("响应时间1", "力1：" + dminforce.ToString());
                m_mainform.baocunRJ("响应时间2", "力2：" + dmaxforce.ToString());

                dstartvol = fstartforce == dmaxforce ? fvolmax : fvolmin;
                dendvol = fendforce == dmaxforce ? fvolmax : fvolmin;

                objini.Writue("自检响应时间", string.Format("{0}{1}", fspeedend, fpowerstart), dstartvol.ToString());
                objini.Writue("自检响应时间", string.Format("{0}{1}", fspeedend, fpowerend), dendvol.ToString());

                m_mainform.DAC.PutVol(dstartvol);//
                DateTime dtwoliusj = DateTime.Now;
                //
                #region 降到开始负荷
                while (true)
                {
                    Thread.Sleep(10);
                    if (m_fspeed <= fspeedend+0.5)
                    {//记录结束滑行时间
                        break;
                    }
                    if (JDhelpClass.DateDiff(DateTime.Now, dtwoliusj) >= 300)
                    {
                        if (fForce > fstartforce + 2)
                        {
                            dstartvol = dstartvol-2;
                        }
                        else if (fForce < fstartforce - 2)
                        {
                            dstartvol = dstartvol+2;
                        }
                        m_mainform.DAC.PutVol(dstartvol);//
                        dtwoliusj = DateTime.Now;
                    }

                    string syy = DateTime.Now.ToString("yyyy");
                    string smm = DateTime.Now.ToString("MM");
                    string sdd = DateTime.Now.ToString("dd");
                    string smul = string.Format("{0}\\{1}\\{2}\\{3}", System.Windows.Forms.Application.StartupPath, syy, smm, sdd);
                    if (!Directory.Exists(smul))
                    {
                        Directory.CreateDirectory(smul);
                    }
                    path = string.Format("{0}\\{1}.ini", smul, "响应时间过程数据");
                    objini.Ini(path);
                    string siniwrite = string.Format("码值：{0}，速度：{1}，力：{2},功率：{3}",
                      dstartvol.ToString("0"), m_fspeed.ToString("0.0"), fForce.ToString("0.0"), (m_fspeed * fForce / 360f).ToString("0.0"));
                    objini.Writue("响应时间过程数据" + DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), siniwrite);
                }
                #endregion
                #region 检测响应时间
                m_mainform.DAC.PutVol(dendvol);//
                DateTime dpinlv = DateTime.Now;
                bool bbzjs = false;
                while (true)
                {
                    Thread.Sleep(10);
                    if (fstartforce > fendforce)
                    {
                        if (fForce < fendforce * 1.1 && !bbzjs)
                        {
                            bbzjs = true;
                            fxysj = JDhelpClass.DateDiff(DateTime.Now, dpinlv);
                            //break;
                        }
                    }
                    else
                    {
                        if (fForce > fendforce * 0.9 && !bbzjs)
                        {
                            bbzjs = true;
                            fxysj = JDhelpClass.DateDiff(DateTime.Now, dpinlv);
                            //break;
                        }
                    }
                    if (m_fspeed < 1)
                        break;
                    if (JDhelpClass.DateDiff(DateTime.Now, dtwoliusj) >= 300)
                    {
                        if (fForce > fendforce + 2)
                        {
                            dendvol--;
                        }
                        else if (fForce < fendforce - 2)
                        {
                            dendvol++;
                        }
                        m_mainform.DAC.PutVol(dendvol);//
                        dtwoliusj = DateTime.Now;
                    }

                    string syy = DateTime.Now.ToString("yyyy");
                    string smm = DateTime.Now.ToString("MM");
                    string sdd = DateTime.Now.ToString("dd");
                    string smul = string.Format("{0}\\{1}\\{2}\\{3}", System.Windows.Forms.Application.StartupPath, syy, smm, sdd);
                    if (!Directory.Exists(smul))
                    {
                        Directory.CreateDirectory(smul);
                    }
                    path = string.Format("{0}\\{1}.ini", smul, "响应时间过程数据");
                    objini.Ini(path);
                    string siniwrite = string.Format("码值：{0}，速度：{1}，力：{2},功率：{3}",
                      dendvol.ToString("0"), m_fspeed.ToString("0.0"), fForce.ToString("0.0"), (m_fspeed * fForce / 360f).ToString("0.0"));
                    objini.Writue("响应时间过程数据" + DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), siniwrite);
                }
                m_mainform.DAC.PutVol(0);//
                #endregion
            }
            catch (Exception )
            { }

        }

        public void Thread1()
        {
            try
            {
                getstart(64);
                Thread.Sleep(1000);
                ctrlshuchu(56, fspeedend, fpowerstart,fpowerend);
                m_mainform.DAC.PutVol(0);//

                MethodInvoker ln = new MethodInvoker(setjcjg);
                this.BeginInvoke(ln);
            }
            catch
            {

            }
            bxc1 = false;
        }
        public void Thread2()
        {
            try
            {
                DateTime dpinlv = DateTime.Now;
                bool bbz = false;
                while (true)
                {
                    Thread.Sleep(10);
                    m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
                    float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataSU[iASMtdz]) - m_mainform.DAC.getjsz("测功力左",  m_mainform.DAC.fAIDataZero[iASMtdz]);
                    float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataSU[iASMtdy]) - m_mainform.DAC.getjsz("测功力右",  m_mainform.DAC.fAIDataZero[iASMtdy]);
                    float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataSU[iASMtdh]) - m_mainform.DAC.getjsz("测功力后",  m_mainform.DAC.fAIDataZero[iASMtdh]);

                    fForce = fzou + fyou + fhou;
                    if (fForce < 0)
                    {
                        fForce = 0;
                    }
                    fpower = m_fspeed * fForce / 360f;
                    if (m_fspeed > 30)
                        bbz = true;
                    if (m_fspeed < 1 && bbz)
                        break;

                    if (JDhelpClass.DateDiff(DateTime.Now, dpinlv) > 500)
                    {
                        dSP[igcsj] = (double)m_fspeed;
                        dPW[igcsj] = fpower;
                        dFC[igcsj] = fForce;
                        dtimex[igcsj] = JDhelpClass.DateDiff(DateTime.Now, dstartgcsj) / 1000;
                        WriteGraph(zedGraphControl1, dSP, dPW, igcsj + 1);
                        igcsj++;
                        dpinlv = DateTime.Now;
                    }
                }

            }
            catch
            {

            }
            bxc2 = false;
            //MethodInvoker ln = new MethodInvoker(setjcjg);
            //this.BeginInvoke(ln);
            //MethodInvoker ln2 = new MethodInvoker(getlilunshijian);
            //this.BeginInvoke(ln2);
            //MethodInvoker ln3 = new MethodInvoker(getwucha);
            //this.BeginInvoke(ln3);
        }

        private void skinButton3_Click(object sender, EventArgs e)
        {
            if (bxc1 || bxc2)
            {
                MessageBox.Show("内部线程还在进行，请等待完成再检测或者关闭软件再打开");
                return;
            }
            idijizu = 2;
            float.TryParse(txtspeed2.Text, out fspeedend);
            float.TryParse(txtstartpower2.Text, out fpowerstart);
            float.TryParse(txtendpower2.Text, out fpowerend);

             m_mainform.DAC.Lift(false);
            Thread.Sleep(1500);

            m_mainform.DAC.PutVol(0);
            Thread.Sleep(1000);
            m_mainform.BianPinQi(true);
            Thread.Sleep(3000);
            m_mainform.BianPinQiSpeed(256 * 40);//设置频率
            bxc1 = true;
            bxc2 = true;
            t1 = new Thread(new ThreadStart(Thread1));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();
            t2 = new Thread(new ThreadStart(Thread2));
            t2.Priority = ThreadPriority.BelowNormal;
            t2.Start();
        }

        private void skinButton4_Click(object sender, EventArgs e)
        {

            if (bxc1 || bxc2)
            {
                MessageBox.Show("内部线程还在进行，请等待完成再检测或者关闭软件再打开");
                return;
            }
            idijizu = 3;
            float.TryParse(txtspeed3.Text, out fspeedend);
            float.TryParse(txtstartpower3.Text, out fpowerstart);
            float.TryParse(txtendpower3.Text, out fpowerend);

             m_mainform.DAC.Lift(false);
            Thread.Sleep(1500);

            m_mainform.DAC.PutVol(0);
            Thread.Sleep(1000);
            m_mainform.BianPinQi(true);
            Thread.Sleep(3000);
            m_mainform.BianPinQiSpeed(256 * 40);//设置频率
            bxc1 = true;
            bxc2 = true;
            t1 = new Thread(new ThreadStart(Thread1));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();
            t2 = new Thread(new ThreadStart(Thread2));
            t2.Priority = ThreadPriority.BelowNormal;
            t2.Start();
        }

        private void skinButton5_Click(object sender, EventArgs e)
        {

            if (bxc1 || bxc2)
            {
                MessageBox.Show("内部线程还在进行，请等待完成再检测或者关闭软件再打开");
                return;
            }
            idijizu = 4;
            float.TryParse(txtspeed4.Text, out fspeedend);
            float.TryParse(txtstartpower4.Text, out fpowerstart);
            float.TryParse(txtendpower4.Text, out fpowerend);

             m_mainform.DAC.Lift(false);
            Thread.Sleep(1500);

            m_mainform.DAC.PutVol(0);
            Thread.Sleep(1000);
            m_mainform.BianPinQi(true);
            Thread.Sleep(3000);
            m_mainform.BianPinQiSpeed(256 * 40);//设置频率
            bxc1 = true;
            bxc2 = true;
            t1 = new Thread(new ThreadStart(Thread1));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();
            t2 = new Thread(new ThreadStart(Thread2));
            t2.Priority = ThreadPriority.BelowNormal;
            t2.Start();
        }

        private void skinButton9_Click(object sender, EventArgs e)
        {

            if (bxc1 || bxc2)
            {
                MessageBox.Show("内部线程还在进行，请等待完成再检测或者关闭软件再打开");
                return;
            }
            idijizu = 5;
            float.TryParse(txtspeed5.Text, out fspeedend);
            float.TryParse(txtstartpower5.Text, out fpowerstart);
            float.TryParse(txtendpower5.Text, out fpowerend);

             m_mainform.DAC.Lift(false);
            Thread.Sleep(1500);

            m_mainform.DAC.PutVol(0);
            Thread.Sleep(1000);
            m_mainform.BianPinQi(true);
            Thread.Sleep(3000);
            m_mainform.BianPinQiSpeed(256 * 40);//设置频率
            bxc1 = true;
            bxc2 = true;
            t1 = new Thread(new ThreadStart(Thread1));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();
            t2 = new Thread(new ThreadStart(Thread2));
            t2.Priority = ThreadPriority.BelowNormal;
            t2.Start();
        }

        private void skinButton8_Click(object sender, EventArgs e)
        {

            if (bxc1 || bxc2)
            {
                MessageBox.Show("内部线程还在进行，请等待完成再检测或者关闭软件再打开");
                return;
            }
            idijizu = 6;
            float.TryParse(txtspeed6.Text, out fspeedend);
            float.TryParse(txtstartpower6.Text, out fpowerstart);
            float.TryParse(txtendpower6.Text, out fpowerend);

             m_mainform.DAC.Lift(false);
            Thread.Sleep(1500);

            m_mainform.DAC.PutVol(0);
            Thread.Sleep(1000);
            m_mainform.BianPinQi(true);
            Thread.Sleep(3000);
            m_mainform.BianPinQiSpeed(256 * 40);//设置频率
            bxc1 = true;
            bxc2 = true;
            t1 = new Thread(new ThreadStart(Thread1));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();
            t2 = new Thread(new ThreadStart(Thread2));
            t2.Priority = ThreadPriority.BelowNormal;
            t2.Start();
        }

        private void skinButton7_Click(object sender, EventArgs e)
        {

            if (bxc1 || bxc2)
            {
                MessageBox.Show("内部线程还在进行，请等待完成再检测或者关闭软件再打开");
                return;
            }
            idijizu = 7;
            float.TryParse(txtspeed7.Text, out fspeedend);
            float.TryParse(txtstartpower7.Text, out fpowerstart);
            float.TryParse(txtendpower7.Text, out fpowerend);

             m_mainform.DAC.Lift(false);
            Thread.Sleep(1500);

            m_mainform.DAC.PutVol(0);
            Thread.Sleep(1000);
            m_mainform.BianPinQi(true);
            Thread.Sleep(3000);
            m_mainform.BianPinQiSpeed(256 * 40);//设置频率
            bxc1 = true;
            bxc2 = true;
            t1 = new Thread(new ThreadStart(Thread1));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();
            t2 = new Thread(new ThreadStart(Thread2));
            t2.Priority = ThreadPriority.BelowNormal;
            t2.Start();
        }

        private void skinButton6_Click(object sender, EventArgs e)
        {

            if (bxc1 || bxc2)
            {
                MessageBox.Show("内部线程还在进行，请等待完成再检测或者关闭软件再打开");
                return;
            }
            idijizu = 8;
            float.TryParse(txtspeed8.Text, out fspeedend);
            float.TryParse(txtstartpower8.Text, out fpowerstart);
            float.TryParse(txtendpower8.Text, out fpowerend);

             m_mainform.DAC.Lift(false);
            Thread.Sleep(1500);

            m_mainform.DAC.PutVol(0);
            Thread.Sleep(1000);
            m_mainform.BianPinQi(true);
            Thread.Sleep(3000);
            m_mainform.BianPinQiSpeed(256 * 40);//设置频率
            bxc1 = true;
            bxc2 = true;
            t1 = new Thread(new ThreadStart(Thread1));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();
            t2 = new Thread(new ThreadStart(Thread2));
            t2.Priority = ThreadPriority.BelowNormal;
            t2.Start();
        }

        private void JDXiangYSJ_Resize_1(object sender, EventArgs e)
        {
            float newx = (this.Width) / x;
            float newy = (this.Height) / y;
            setControls(newx, newy, this);
        }

        private void skinButton10_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.Lift(true);
        }

        private void skinButton11_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.Lift(false);
        }
    }
}
